<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>

 

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
</head>
<body>
<form action="../../index.html" method="post" class="definewidth m20">
<input type="hidden" name="id" value="{$user.id}" />
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">资源名称</td>
            <td><input type="text" name="menuname" readonly="readonly" value="挂号信息管理"/></td>
        </tr>
        <tr>
            <td class="tableleft">url</td>
            <td><input type="text" name="menuurl" value="query.action"/></td>
        </tr>
        <tr>
            <td class="tableleft">是否有效</td>
            <td>
                <input type="radio" name="status" value="1" checked/> 有效
              <input type="radio" name="status" value="0" /> 无效
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <input class="btn btn-primary" type="button" value="更新"onclick="genxin()"/>&nbsp;&nbsp;<button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
<script>
    $(function () {       
		$('#backid').click(function(){
				window.location.href="index.html";
		 });
        //获取id
        let mId = window.location.href.split("?")[1].split("=")[1];

        $.ajax({
            url: "http://localhost:8080/menu/selectByPrimaryKey",
            data: {
                'integer': mId,
            },
            type: 'POST',
            dataType: 'json',
            success: function (response) {

                let menu = response.data.menu;

                $("input[name='menuname']").val(menu.mName);
                $("input[name='menuurl']").val(menu.mUrl);
                //$("input[name='status']").val(menu.mState);
                $("[name='status'][value='mState']").prop("checked", "checked");

            }
        })
    });
    function genxin(){
        var menuName = $("input[name='menuname']").val();
        var menuUrl = $("input[name='menuurl']").val();
        var menuState = $("input[name='status']:checked").val();
        if(menuUrl == null || menuUrl== ''){
            alert("url为空");
            return;
        }
        initData(menuName,menuUrl,menuState);

    }
    function initData(menuname,menuurl,state) {
        $.ajax({
            url: "http://localhost:8080/menu/updateMenu",
            data: {
                'menuName':menuname,
                'menuUrl': menuurl,
                'menuState': state,

            },
            type: 'POST',
            dataType: 'json',
            success: function (resp) {
                if (resp.response.flag) {
                    window.location.href = "index.html";
                }
            }
        })
    }

</script>